using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace blimp_compass
{
    public partial class Form1 : Form
    {
        private CompassSerial serialCompass;

        public Form1()
        {
            InitializeComponent();
        }

        private void tmrCompassPoll_Tick(object sender, EventArgs e)
        {
            double heading = serialCompass.GetHeading() * (Math.PI / 180);
            compassControl1.Heading = heading;

        }

        private void compassControl1_Load(object sender, EventArgs e)
        {

        }

        private void compassControl1_Click(object sender, EventArgs e)
        {
            double heading = serialCompass.GetHeading() * (Math.PI / 180);
            compassControl1.Heading = heading;

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            

        }

        private void Form1_Click(object sender, EventArgs e)
        {
            
        }

        private void btnCalibrate_Click(object sender, EventArgs e)
        {
            if (btnCalibrate.Text == "Stop")
            {
                tmrCompassPoll.Enabled = true;
                serialCompass.StopCalibration();
                btnCalibrate.Text = "Calibrate";
            }
            else
            {
                tmrCompassPoll.Enabled = false;
                serialCompass.StartCalibration();
                btnCalibrate.Text = "Stop";
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            serialCompass =  new CompassSerial(txtCOM.Text);
            tmrCompassPoll.Enabled = true;

        }
    }
}